home *** CD-ROM | disk | FTP | other *** search
/ Young Minds / Young Minds Interactive CD-ROM.ISO / umoria / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1988-07-28  |  5.4 KB  |  179 lines

  1. /* Moria Version 4.8    COPYRIGHT (c) Robert Alan Koeneke        */
  2. /*                                                                       */
  3. /*       I lovingly dedicate this game to hackers and adventurers        */
  4. /*       everywhere...                                                   */
  5. /*                                                                       */
  6. /*                                                                       */
  7. /*       Designer and Programmer : Robert Alan Koeneke                   */
  8. /*                                 University of Oklahoma                */
  9. /*                                                                       */
  10. /*       Assistant Programmers   : Jimmey Wayne Todd                     */
  11. /*                                 University of Oklahoma                */
  12. /*                                                                       */
  13. /*                                 Gary D. McAdoo                        */
  14. /*                                 University of Oklahoma                */
  15. /*                                                                       */
  16. /*       UNIX Port               : James E. Wilson                       */
  17. /*                                 UC Berkeley                           */
  18. /*                                 wilson@ernie.Berkeley.EDU             */
  19. /*                                 ucbvax!ucbernie!wilson                */
  20. /*                                                                       */
  21. /*       Moria may be copied and modified freely as long as the above    */
  22. /*       credits are retained.  No one who-so-ever may sell or market    */
  23. /*       this software in any form without the expressed written consent */
  24. /*       of the author Robert Alan Koeneke.                              */
  25. /*                                                                       */
  26.  
  27. #include <curses.h>
  28. #include <sys/types.h>
  29.  
  30. #include "constants.h"
  31. #include "config.h"
  32. #include "types.h"
  33. #include "externs.h"
  34.  
  35. #ifdef USG
  36. #include <string.h>
  37. #else
  38. #include <strings.h>
  39. #endif
  40.  
  41. #if defined(ultrix) || defined(sun) || defined(USG)
  42. int getuid();
  43. int getgid();
  44. #else
  45. uid_t getuid();
  46. uid_t getgid();
  47. #endif
  48.  
  49. #if defined(ultrix) || defined(USG)
  50. void perror();
  51. void exit();
  52. #endif
  53.  
  54. extern int key_bindings;
  55.  
  56. /* Initialize, restore, and get the ball rolling...    -RAK-    */
  57. main(argc, argv)
  58. int argc;
  59. char *argv[];
  60. {
  61.   /* call this routine to grab a file pointer to the highscore file *
  62.   /* and prepare things to relinquish setuid privileges */
  63.   init_scorefile();
  64.  
  65.   if (0 != setuid(getuid()))
  66.     {
  67.       perror("Gack!  Can't set permissions correctly!  Exiting!\n");
  68.       exit(0);
  69.     }
  70.   if (0 != setgid(getgid()))
  71.     {
  72.       perror("Gack!  Can't set group id correctly!  Exiting!\n");
  73.       exit(0);
  74.     }
  75.  
  76.   /* use curses */
  77.   init_curses();
  78.  
  79.   /* catch those nasty signals */
  80.   /* must come after init_curses as some of the signal handlers use curses */
  81.   init_signals();
  82.  
  83.   /* Build the secret wizard and god passwords    */
  84.   bpswd();
  85.  
  86.   /* check for user interface option */
  87.   key_bindings = KEY_BINDINGS;
  88.   if (argc >= 2)
  89.     {
  90.       if (!strcmp(argv[1], "-r"))
  91.         {
  92.           key_bindings = ROGUE_LIKE;
  93.           argv[1][0] = '\0';
  94.         }
  95.       if (!strcmp(argv[1], "-o"))
  96.     {
  97.       key_bindings = ORIGINAL;
  98.       argv[1][0] = '\0';
  99.     }
  100.       if (!strcmp(argv[1], "-s"))
  101.     {
  102.       display_scores();
  103.       exit_game();
  104.     }
  105.     }
  106.  
  107.   /* Check operating hours             */
  108.   /* If not wizard  No_Control_Y               */
  109.   /* Check or create hours.dat, print message    */
  110.   /* if last arg is ^ then start as wizard, can not restore game also */
  111.   if (argc >= 2)
  112.     intro(argv[argc - 1]);
  113.   else
  114.     intro("");
  115.  
  116.   /* Some necessary initializations        */
  117.   /* all made into constants or initialized in variables.c */
  118.  
  119.   /* Grab a random seed from the clock        */
  120.   init_seeds();
  121.  
  122.   /* Sort the objects by level            */
  123.   sort_objects();
  124.  
  125.   /* Init monster and treasure levels for allocate */
  126.   init_m_level();
  127.   init_t_level();
  128.  
  129.   /* Init the store inventories            */
  130.   store_init();
  131.   if (COST_ADJ != 1.00)  price_adjust();
  132.  
  133.   /* Generate a character, or retrieve old one...    */
  134.   if ((argc > 1) && strlen(argv[argc-1]))
  135.     {     /* Retrieve character    */
  136.       generate = get_char(argv[argc-1]);
  137.       change_name();
  138.       magic_init();
  139.     }
  140.   else
  141.     {     /* Create character      */
  142.       create_character();
  143.       char_inven_init();
  144.       if (class[py.misc.pclass].mspell)
  145.     {         /* Magic realm   */
  146.       (void) learn_spell(&msg_flag);
  147.       gain_mana(int_adj());
  148.     }
  149.       else if (class[py.misc.pclass].pspell)
  150.     {         /* Clerical realm*/
  151.       (void) learn_prayer();
  152.       gain_mana(wis_adj());
  153.     }
  154.       py.misc.cmana = (double)py.misc.mana;
  155.       magic_init();
  156.       generate = TRUE;
  157.     }
  158.  
  159.   /* Begin the game                */
  160.   /*    This determines the maximum player level    */
  161.   /* must be one less than real value so that prt_experience will work
  162.      correctly, otherwise it is possible to reach level 41 */
  163.   player_max_exp = player_exp[MAX_PLAYER_LEVEL-1] * py.misc.expfact - 1;
  164.   clear_screen(0, 0);
  165.   prt_stat_block();
  166.   /* prevent ^c quit from entering score into scoreboard until this point */
  167.   character_generated = 1;
  168.  
  169.   /* Loop till dead, or exit            */
  170.   while(!death) {
  171.     if (generate)  generate_cave();         /* New level     */
  172.     dungeon();                                  /* Dungeon logic */
  173.     generate = TRUE;
  174.   }
  175.   upon_death();                         /* Character gets buried */
  176.   /* should never reach here, but just in case */
  177.   return (0);
  178. }
  179.